package service;

import java.util.List;

import dao.CartDao;
import pojo.Cart;

public class CartService {
	CartDao cdao;
	//编辑数量

	public int editCart(int cid,int num) {
		int flag=0;
		cdao=new CartDao();
		flag=cdao.updateNumByCID(cid, num);
		return flag;
	}
	//购买成功
	public int buyCart(Cart c) {
		int flag=0;
		cdao=new CartDao();
		Cart cart=cdao.getCartByUIDandPID(c);
		if(cart==null) {//商品不存在
			flag=cdao.insertCart(c);
						
		}else {//商品存在，修改数量
			flag=cdao.updateNumByUIDandPID(cart);
					
			}
		
		return flag;
		
	}
	public List<Cart> showCartsByUID(String c_name){
		cdao=new CartDao();
		List<Cart> list=cdao.showCarts(c_name);
		return list;
	}
	public int delcart(String c_name,String p_id) {
		int flag=0;
		cdao=new CartDao();
		flag=cdao.delCart(c_name, p_id);
		return flag;
		
	}
	public int insertCart(Cart c) {
		cdao=new CartDao();
		int flag=cdao.insertCart(c);
		return flag;
	}
	
	

}